﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Oracle;
using System.Data.Common;

namespace GgCarControl
{
    public partial class SAT_ST : DockContent
    {
        public SAT_ST()
        {
            InitializeComponent();
        }
        public static Database db =
             new OracleDatabase("Data Source=DG;User ID=dgrfid;Password=dgrfid;Unicode=True;Load Balance Timeout=1000");
        DataTable dt;

        private void button2_Click(object sender, EventArgs e)
        {
            load_data();
        }

        private void load_data()
        {
            //Begin time value
            string date_time_begin = this.dateTimePicker1.Value.ToString();
            int ind = date_time_begin.IndexOf(" ");
            string date_value_begin = date_time_begin.Substring(0, ind);
            //End time value
            string date_time_end = this.dateTimePicker2.Value.ToString();
            int ind2 = date_time_end.IndexOf(" ");
            string date_value_end = date_time_end.Substring(0, ind2);

            //string sql = "select logintime as 登记时间,shipper_name as 船名,BILL_NO as 提单号,cargoname as 货名,yard as 地点,cardadd as 发卡地点,truckno as  车号,stackname as 垛名,pieces as 件数,IOYARDID,TRUCKSTATUS from TRUCK_LOGIN" +
            //    " where ioyardid=1 and trunc(logintime)<=to_date('" + date_value_end + "','yyyy-mm-dd') and trunc(logintime)>=to_date('" + date_value_begin + "','yyyy-mm-dd') order by logintime desc,TRUCKSTATUS";
            string sql = "select cargoname as 货名,count(truckno) as 车数,DECODE(to_number(TRUCKSTATUS),0,'已登记',1,'已发指令',2,'已放车',3,'已进门',4,'已理货',5,'已出门') as 状态,sum(pieces) as 总件数,sum(WEIGHT) as 总重量 from V_TRUCK_CARGO_LOGIN_ALL " +
                " where ioyardid=0 and truckstatus<>9 and trunc(logintime)<=to_date('" + date_value_end + "','yyyy-mm-dd') and trunc(logintime)>=to_date('" + date_value_begin + "','yyyy-mm-dd')" +
                "group by cargoname,truckstatus ";
            //select cargoname,truckstatus,count(truckno) as numbers,sum(pieces) pieces,sum(WEIGHT) WEIGHT from truck_login_all group by cargoname,truckstatus
            dt = db.ExecuteDataSet(db.GetSqlStringCommand(sql.ToString())).Tables[0];

            this.dataGridView1.AutoGenerateColumns = true;
            this.dataGridView1.AllowUserToAddRows = false;
            this.dataGridView1.DataSource = dt;        }

        private void SAT_ST_Load(object sender, EventArgs e)
        {
            load_data();
        }
    }
}
